package com.carefree.system.modules.admin.controller;

import com.carefree.common.core.PageUtils;
import com.carefree.common.core.Result;
import com.carefree.system.modules.admin.entity.LoginLogEntity;
import com.carefree.system.modules.admin.service.LoginLogService;
import com.carefree.system.modules.admin.service.OperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:LogsController
 * @Description: 日志
 * @Author Tengbin tengbin234@163.com
 */
@Api(tags = "日志查询")
@RestController
@RequestMapping("/sys/logs")
public class LogsController {

    @Resource
    private OperLogService operLogService;

    @Resource
    private LoginLogService loginLogService;


    /**
     * 分页+条件查询操作日志
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "分页+条件查询操作日志信息")
    @GetMapping("/operlogs")
    @PreAuthorize("hasAuthority('btn:operlog:list')")
    public Result<PageUtils> operLogList(@RequestParam Map<String, Object> params) {
        PageUtils pageUtils = operLogService.queryPage(params);
        return Result.success(pageUtils);
    }

    /**
     * 分页+条件查询登录日志
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "分页+条件查询登录日志信息")
    @GetMapping("/loginlogs")
    @PreAuthorize("hasAuthority('btn:loginlog:list')")
    public Result<PageUtils> loginLogList(@RequestParam Map<String, Object> params) {
        PageUtils pageUtils = loginLogService.queryPage(params);
        return Result.success(pageUtils);
    }

    /**
     * 根据当前登录的用户名查询当前用户的登录日志信息
     *
     * @param username 用户名
     * @return
     */
    @ApiOperation(value = "根据当前登录的用户名查询当前用户的登录日志信息")
    @GetMapping("/loginlogs/{username}")
    public Result<List<LoginLogEntity>> queryLooginLogByUserName(@PathVariable String username) {
        return loginLogService.queryLooginLogByUserName(username);
    }

}
